package com.tencent.wxcloudrun.controller;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tencent.wxcloudrun.config.ApiResponse;
import com.tencent.wxcloudrun.manager.UserCardManager;
import com.tencent.wxcloudrun.vo.request.card.*;
import com.tencent.wxcloudrun.vo.response.card.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author ZhaoZiYin
 * @Date 2025/2/20
 * @Description 用户卡片控制器
 */
@Api(tags = "用户卡片控制器")
@Slf4j
@RestController
@Validated
@RequestMapping("/api/user/card")
public class UserCardController {

    @Resource
    private UserCardManager userCardManager;

    @ApiOperation("申请卡片")
    @PostMapping(value = "/apply")
    public ApiResponse<UserCardApplyResVo> apply(@RequestBody @Valid UserCardApplyReqVo reqVo) {
        return ApiResponse.ok(userCardManager.apply(reqVo));
    }

    @ApiOperation("取消申请卡片")
    @PostMapping(value = "/cancelApply")
    public ApiResponse<UserCardCancelApplyResVo> cancelApply(@RequestBody @Valid UserCardCancelApplyReqVo reqVo) {
        return ApiResponse.ok(userCardManager.cancelApply(reqVo));
    }

    @ApiOperation("查询申请记录")
    @PostMapping(value = "/queryApply")
    public ApiResponse<UserCardQueryApplyResVo> queryApply(@RequestBody @Valid UserCardQueryApplyReqVo reqVo) {
        return ApiResponse.ok(userCardManager.queryApply(reqVo));
    }

    @ApiOperation("分页查询申请列表")
    @PostMapping(value = "/listApply")
    public ApiResponse<IPage<UserCardListApplyResVo>> listApply(@RequestBody @Valid UserCardListApplyReqVo reqVo) {
        return ApiResponse.ok(userCardManager.listApply(reqVo));
    }

    @ApiOperation("查询用户卡片")
    @PostMapping(value = "/list")
    public ApiResponse<UserCardListResVo> list(@RequestBody @Valid UserCardListReqVo reqVo) {
        return ApiResponse.ok(userCardManager.listCard(reqVo));
    }

    @ApiOperation("查询用户卡片记录")
    @PostMapping(value = "/listRecord")
    public ApiResponse<UserCardListRecordResVo> listRecord(@RequestBody @Valid UserCardListRecordReqVo reqVo) {
        return ApiResponse.ok(userCardManager.listRecord(reqVo));
    }

    @ApiOperation("使用卡片")
    @PostMapping(value = "/use")
    public ApiResponse<UserCardUseResVo> use(@RequestBody @Valid UserCardUseReqVo reqVo) {
        return ApiResponse.ok(userCardManager.use(reqVo));
    }

    @ApiOperation("导出使用卡片记录")
    @PostMapping(value = "/exportUseRecord")
    public ApiResponse<UserCardExportRecordResVo>
        exportUseRecord(@RequestBody @Valid UserCardExportUseRecordReqVo reqVo) {
        return ApiResponse.ok(userCardManager.exportUseRecord(reqVo));
    }

}
